import sys

students = []

def menu():
    print("1.新增学生信息")
    print("2.显示所有学生信息")
    print("3.根据姓名查找学生信息")
    print("4.删除学生信息")
    print("0.退出")
    choice = input("请输入：")
    return int(choice)

def insert():
    print("开始新增：")
    student_id = input("请输入学生学号：")
    name = input("请输入学生姓名：")
    gender = input("请输入学生性别：")
    if gender not in ("男","女"):
        print("性别错误！新增学生失败！")
        return
    class_name = input("请输入班级：")
    #使用字典表示学生信息
    student = {
        "学号": student_id,
        "姓名": name,
        "性别": gender,
        "班级": class_name
    }
    global students
    students.append(student)
    print("新增完毕！")

def show():
    print("开始显示：")
    for s in students:
        print(f"{s["学号"]}\t{s["姓名"]}\t{s["性别"]}\t{s["班级"]}")
    print(f"共有{len(students)}条数据！")
    print("显示完毕！")

def find():
    name = input(f"请输入要查找的同学姓名：")
    count = 0
    for i in students:
        if name == i["姓名"]:
            print(f"{i["学号"]}\t{i["姓名"]}\t{i["性别"]}\t{i["班级"]}")
            count += 1
    print(f"查找完毕！共查找到{count}条数据！")

def delete():
    print("开始删除：")
    count = 0
    student_id = input("请输入要删除同学的学号：")
    for i in students:
        if student_id == i["学号"]:
            print(f"{i["姓名"]}同学的信息已删除！")
            students.remove(i)
            count += 1
    print(f"删除完毕！共删除{count}条记录！")


def main():
    print("+---------------------------------------+")
    print("|                                       |")
    print("|          欢迎来到学生信息管理系统          |")
    print("|                                       |")
    print("+---------------------------------------+")
    while True:
        choice = menu()

        if choice == 0:
            print("goodbye!")
            sys.exit(0)

        elif choice == 1:
            insert()

        elif choice == 2:
            show()

        elif choice == 3:
            find()

        elif choice == 4:
            delete()

        else:
            print("输入非法，请重新输入：")

main()